<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page isELIgnored="false"%>
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
     
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/pintuer.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/admin/css/admin.css">
    <script src="${pageContext.request.contextPath}/admin/js/jquery.js"></script>
    <script src="${pageContext.request.contextPath}/admin/js/pintuer.js"></script>  
    
</head>
<body>
<div class="panel admin-panel">
  <div class="panel-head"><strong class="icon-reorder"> 字典类型列表</strong></div>
  <div class="padding border-bottom">
      <ul class="search" style="padding-left:10px;">
         <li> 
        	<a class="button border-yellow" href="${pageContext.request.contextPath}/dictionaryType/add"><span class="icon-plus-square-o"></span> 添加字典类型</a>
        </li>
         <li>
                               页数:
          <select id="pageNum" name="s_ishome" class="input" onchange="changesearch()" style="width:60px; line-height:17px; display:inline-block">
          </select>
         <li>
         <li>
                               字典类型编码:
          <input type="text" placeholder="字典类型编码" id="dicCode" class="input" style="width:140px; line-height:17px;display:inline-block" />
         </li>
		 <li>
		      字典类型名称:
          <input type="text" placeholder="字典类型名称" name="dicName" class="input" style="width:140px; line-height:17px;display:inline-block" />
         </li>
          <a href="javascript:void(0)" class="button border-main icon-search" onclick="changesearch()" > 搜索</a></li>
      	  <a href="javascript:void(0)" class="button border-main icon-undo"  onclick="reset()" > 重置</a></li>
      </ul>
    </div>
  <table class="table table-hover text-center">
    <tr id="tbHead">
      <th width="120">字典类型编码</th>  
      <th width="120">字典类型名称</th>  
      <th width="120">顺序号</th>     
      <th width="120">操作</th>
    </tr>
  </table>
</div>

<script>
$(function(){
	$.ajax({
	 	type:'post',
	 	url:'${pageContext.request.contextPath}/dictionaryType/loadIndexDataList',
	 	data:{pageNo:1,pageSize:10},
	 	dataType:'json',
	 	cache:false,
	 	success:function(data)
	 	{	
	 		if(data.success)
	 		{
	 			$("#tbHead").after("");
	 			data = data.entity;
	 			var dataList = data.data;
	 			var totalRow = data.totalRow;
	 			var totalPage = data.totalPage;	
	 			for(var element=dataList.length-1;element>=0;element--){
	 				var htmlCode = buildTable(dataList[element]);
		 			$("#tbHead").after(htmlCode);
	 			}
	 			var htmlCodeStr= "";
	 			for(var pageStart = 1;pageStart<=totalPage;pageStart++){
	 				htmlCodeStr+="<option value='"+pageStart+"'>"+pageStart+"</option>"
	 			}
	 			$("#pageNum").html(htmlCodeStr);
	 		}
	 		else
	 		{
	 			alert(data.message);
	 		}
	 	},
	 	error:function(data)
	 	{
	 		alert('系统出现异常!');
	 	}
	});
	
});

function buildTable(element){
		console.info(element.orderNo);
		var htmlTemplate = 
		  "<tr name='tbBody'>" +
	      "<td>"+element.dicCode+"</td>"+ 
	      "<td>"+element.dicName+"</td>"+      
	      "<td>"+element.orderNo+"</td>"+      
	      "<td><div class='button-group'>"+
	        "<a type='button' class='button border-main' href='javascript:void(0)' onclick='edit(\""+element.id+"\")'><span class='icon-edit'></span>修改</a>"+
	        "<a class='button border-red' href='javascript:void(0)' onclick='del(\""+element.id+"\")'><span class='icon-trash-o'></span>删除</a>"+
	      "</div>"+
	     " </td>"+
	    "</tr>";
	 return htmlTemplate;
}

function reset(){
	$("#menuPath").val("");
	$("#menuCode").val("");
	$("#menuType").val("");
	$("#pageNum").val("1");
}

function doSearch(){
	var pageNum = $("#pageNum").val();
	$.ajax({
	 	type:'post',
	 	url:'${pageContext.request.contextPath}/dictionaryType/showData',
	 	data:{pageNo:pageNum,pageSize:10},
	 	dataType:'json',
	 	cache:false,
	 	success:function(data)
	 	{	
	 		if(data.success)
	 		{
	 			$("#tbHead").after("");
	 			var dataList = data.data;
	 			var totalRow = data.totalRow;
	 			var totalPage = data.totalPage;	
	 			for(var element=0;element<dataList.length;element++){
	 				var htmlCode = buildTable(dataList[element]);
		 			$("#tbHead").after(htmlCode);
	 			}
	 			var htmlCodeStr= "";
	 			for(var pageStart = 1;pageStart<=totalPage;pageStart++){
	 				htmlCodeStr+="<option value='"+pageStart+"'>"+pageStart+"</option>"
	 			}
	 			$("#pageNum").html(htmlCodeStr);
	 		}
	 		else
	 		{
	 			alert(data.message);
	 		}
	 	},
	 	error:function(data)
	 	{
	 		alert('系统出现异常!');
	 	}
	});
}

//编辑
function edit(id)
{
	location.href = "${pageContext.request.contextPath}/dictionaryType/edit?id="+id;
}

//删除
function del(id){
	if(confirm("您确定要删除吗?"))
	{
	 $.ajax({
		 	type:'post',
		 	url:'${pageContext.request.contextPath}/dictionaryType/remove',
		 	data:{id:id},
		 	dataType:'json',
		 	cache:false,
		 	success:function(data)
		 	{ 
		 		$("tr[name='tbBody']").remove();
		 		$.ajax({
		 		 	type:'post',
		 		 	url:'${pageContext.request.contextPath}/dictionaryType/loadIndexDataList',
		 		 	data:{pageNo:1,pageSize:10},
		 		 	dataType:'json',
		 		 	cache:false,
		 		 	success:function(data)
		 		 	{	
		 		 		if(data.success)
		 		 		{
		 		 			data = data.entity;
		 		 			var dataList = data.data;
		 		 			var totalRow = data.totalRow;
		 		 			var totalPage = data.totalPage;	
		 		 			for(var element=dataList.length-1;element>=0;element--){
		 		 				var htmlCode = buildTable(dataList[element]);
		 			 			$("#tbHead").after(htmlCode);
		 		 			}
		 		 			var htmlCodeStr= "";
		 		 			for(var pageStart = 1;pageStart<=totalPage;pageStart++){
		 		 				htmlCodeStr+="<option value='"+pageStart+"'>"+pageStart+"</option>"
		 		 			}
		 		 			$("#pageNum").html(htmlCodeStr);
		 		 		}
		 		 		else
		 		 		{
		 		 			alert(data.message);
		 		 		}
		 		 	},
		 		 	error:function(data)
		 		 	{
		 		 		alert('系统出现异常!');
		 		 	}
		 		});
		 	},
		 	error:function(data)
		 	{
		 		alert('系统出现异常!');
		 	}
		});
	}
}
</script>
</body>
</html>